package com.yenlien.traceyun.usercenter.dao;

import com.yenlien.traceyun.usercenter.entity.CustomAppVersion;
import com.yenlien.traceyun.webase.dao.BaseJpaDao;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import java.util.Collection;
import java.util.List;

/**
 * @author: bigwangy@sina.com
 * @create: 2020-07-29
 * @description:
 **/
public interface CustomAppVersionDao extends BaseJpaDao<CustomAppVersion> {
    CustomAppVersion findById(String id);

    public List<CustomAppVersion> findByCustomAppId(String customAppId);

    public List<CustomAppVersion> findByCustomAppIdIn(Collection<String> ids);

    @Query(value = "select cav from CustomAppVersion cav where cav.id in (select ccav.customAppVersionId from CompanyCustomAppVersion ccav where ccav.companyId=?1)")
    public List<CustomAppVersion> findByCompanyId(String companyId);

    @Query(value = "SELECT tcav.* FROM t_company_customapp_version tccv JOIN t_custom_app_version tcav ON tccv.custom_app_version_id = tcav.id WHERE tccv.company_id = ?1", nativeQuery = true)
    List<CustomAppVersion> getCustomAppVersion(String companyId);
//    CustomAppVersion getCustomAppVersion(String companyId);

    @Transactional
    @Modifying
    @Query(value = "update CustomAppVersion c set c.maxPrint=?1 where c.customAppId=?2")
    Integer updateMaxPrint(long maxPrint, String customAppId);

    @Transactional
    @Modifying
    @Query(value = "update CustomAppVersion c set c.maxScan=?1 where c.customAppId=?2")
    Integer updateMaxScan(int maxScan, String customAppId);
}
